package com.yss.sofa.report.engine.cell.visible.result;

import java.util.Map;

import com.yss.sofa.report.engine.Const;
import com.yss.sofa.report.engine.cell.ReportCell;
import com.yss.sofa.report.engine.cell.page.PageCell;
import com.yss.sofa.report.engine.cell.visible.VisibleCell;

public class ResultCell extends VisibleCell {
	private static final long serialVersionUID = 6815904514383342321L;
	public static enum ForceMergeTo {
		FORCE_MERGE_TO_N,
		FORCE_MERGE_TO_H,
		FORCE_MERGE_TO_V,
	}
	protected int mergeTimes;
	protected String forceMerge;
	protected ForceMergeTo forceMergeTo;
	protected String style;
	protected String html; 
	protected int styleR;
	protected int styleC;
	//原始的坐标
	protected int fromRbegin;
	protected int fromCbegin;
	protected int fromRend;
	protected int fromCend;
	protected void init() {
		super.init();
		this.type=Const.REPORT_CELL_TYPE_RESULT;
		this.mergeTimes=1;
		this.forceMerge="";
		this.forceMergeTo=ForceMergeTo.FORCE_MERGE_TO_N;
		this.style="";
		this.html="";
		this.styleR=-1;
		this.styleC=-1;
	}
	public void assignTo(ReportCell cell){
		ResultCell _=(ResultCell)cell;
		super.assignTo(_);
		_.mergeTimes=this.mergeTimes;
		_.forceMerge=this.forceMerge;
		_.forceMergeTo=this.forceMergeTo;
		_.style=this.style;
		_.html=this.html;
		_.styleR=this.styleR;
		_.styleC=this.styleC;
		_.fromRbegin=this.fromRbegin;
		_.fromCbegin=this.fromCbegin;
		_.fromRend=this.fromRend;
		_.fromCend=this.fromCend;
	}
	public ResultCell create(){
		ResultCell _=new ResultCell();
		this.assignTo(_);
		return _;
	}
	public String getValue(){
		throw new UnsupportedOperationException();
	}
	public Map<String,String> getRecord(){
		throw new UnsupportedOperationException();
	}
	public Map<String,String> getAttr(){
		throw new UnsupportedOperationException();
	}
	public int getMergeTimes() {
		return mergeTimes;
	}
	public boolean isColAutoSize(int col,PageCell page){
		if(page.isDynamicSize()==false){
			return false;
		}
		int index=(col-cbegin);
		index=index % (fromCend-fromCbegin+1);
		return page.getCol(cfrom+index).isAutoSize();
	}
	public boolean isRowAutoSize(int row,PageCell page){
		if(page.isDynamicSize()==false){
			return false;
		}
		int index=(row-rbegin);
		index=index % (fromRend-fromRbegin+1);
		return page.getRow(rfrom+index).isAutoSize();
	}
	public int getW(int col,PageCell page) {
		int index=(col-cbegin);
		index=index % (fromCend-fromCbegin+1);
		return page.getCol(cfrom+index).getWidth();
	}
	@SuppressWarnings("unused")
	private int getColfrom(int col){
		int index=(col-cbegin);
		index=index % (fromCend-fromCbegin+1);
		return cfrom+index;
	}
	public int getH(int row,PageCell page) {
		int index=(row-rbegin);
		index=index % (fromRend-fromRbegin+1);
		return page.getRow(rfrom+index).getHeight();
	}
	@SuppressWarnings("unused")
	private int getRowfrom(int row){
		int index=(row-rbegin);
		index=index % (fromRend-fromRbegin+1);
		return rfrom+index;
	}
	public boolean isEscape(PageCell page){
		return page.getCol(cfrom).isEscape() || page.getRow(rfrom).isEscape();
	}
	public void setForceMergeTo(ForceMergeTo forceMergeTo) {
		this.forceMergeTo = forceMergeTo;
	}
	public boolean needForceMerge() {
		return Boolean.parseBoolean(forceMerge);
	}
	public String getForceMerge() {
		return forceMerge;
	}
	public void setForceMerge(String forceMerge) {
		this.forceMerge = forceMerge;
	}
	public ForceMergeTo getForceMergeTo() {
		return forceMergeTo;
	}
	public String getHtml() {
		return html;
	}
	public String getStyle() {
		return style;
	}
	public int getStyleRfrom(){
		return (styleR<0)?rfrom:styleR;
	}
	public int getStyleCfrom(){
		return (styleC<0)?cfrom:styleC;
	}
	/**
	 * 对于动态样式，其样式是从外部单元格获取的，而不是从RC-from中的获取的
	 */
	public void setStyleFrom(int r,int c){
		this.styleR=r;
		this.styleC=c;
	}
}
